package elitech.vietnam.myfashion;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import elitech.vietnam.myfashion.extend.TabFactory;
import elitech.vietnam.myfashion.view.IndicatorView;

public class TabsActivity extends FragmentActivity implements OnTabChangeListener {
	
	private static final String BESTOFDAY = "BOD";
	private static final String BESTOFWEEK = "BOW";
	private static final String CATEGORY = "CAT";
	private static final String STYLER = "STY";
	private static final String MYSTYLE = "MST";
	private static final String MYSHOPPING = "MYS";
	private static final String SETTING = "SET";
	
	private TabHost mTabHost;
	private TabSpec mSpec;

	public int mScreenWidth, mScreenHeight;
	public View[] mBuffer;
	public int mListWeekLenght, mListStyleLenght, mListMyStyleLenght, mListFavorLenght;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tablayout);
		mTabHost = (TabHost) findViewById(android.R.id.tabhost);
		mTabHost.setup();

		DisplayMetrics metrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(metrics);
		mScreenWidth = metrics.widthPixels; mScreenHeight = metrics.heightPixels;
		
		mSpec=mTabHost.newTabSpec(BESTOFDAY); 
		mSpec.setContent(new TabFactory(this, BESTOFDAY)); 
		mSpec.setIndicator(new IndicatorView(this, getString(R.string.bestoftoday))); 
		mTabHost.addTab(mSpec);
		
		mSpec=mTabHost.newTabSpec(BESTOFWEEK); 
		mSpec.setContent(new TabFactory(this, BESTOFWEEK)); 
		mSpec.setIndicator(new IndicatorView(this, getString(R.string.bestofweek))); 
		mTabHost.addTab(mSpec);
		
		mSpec=mTabHost.newTabSpec(CATEGORY); 
		mSpec.setContent(new TabFactory(this, CATEGORY)); 
		mSpec.setIndicator(new IndicatorView(this, getString(R.string.category))); 
		mTabHost.addTab(mSpec);
		
		mSpec=mTabHost.newTabSpec(STYLER); 
		mSpec.setContent(new TabFactory(this, STYLER)); 
		mSpec.setIndicator(new IndicatorView(this, getString(R.string.styler))); 
		mTabHost.addTab(mSpec);
		
		mSpec=mTabHost.newTabSpec(MYSTYLE); 
		mSpec.setContent(new TabFactory(this, MYSTYLE)); 
		mSpec.setIndicator(new IndicatorView(this, getString(R.string.mystyle))); 
		mTabHost.addTab(mSpec);
		
		mSpec=mTabHost.newTabSpec(MYSHOPPING); 
		mSpec.setContent(new TabFactory(this, MYSHOPPING)); 
		mSpec.setIndicator(new IndicatorView(this, getString(R.string.myshopping))); 
		mTabHost.addTab(mSpec);
		
		mSpec=mTabHost.newTabSpec(SETTING); 
		mSpec.setContent(new TabFactory(this, SETTING)); 
		mSpec.setIndicator(new IndicatorView(this, getString(R.string.setting))); 
		mTabHost.addTab(mSpec);
		
		mTabHost.setCurrentTab(0);
		mTabHost.getTabWidget().getChildAt(0).setBackgroundColor(getResources().getColor(R.color.light_orange));
		mTabHost.setOnTabChangedListener(this);
	}

	@Override
	public void onTabChanged(String tabId) {
		if(tabId.equals(BESTOFDAY)){
			mTabHost.getTabWidget().getChildAt(0).setBackgroundColor(getResources().getColor(R.color.light_orange));
			mTabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(3).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(4).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(5).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(6).setBackgroundColor(Color.TRANSPARENT);
			mBuffer = new View[0];
			return;
		}
		if(tabId.equals(BESTOFWEEK)){
			mTabHost.getTabWidget().getChildAt(1).setBackgroundColor(getResources().getColor(R.color.light_orange));
			mTabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(3).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(4).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(5).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(6).setBackgroundColor(Color.TRANSPARENT);
			mBuffer = new View[mListWeekLenght];
			return;
		}
		if(tabId.equals(CATEGORY)){
			mTabHost.getTabWidget().getChildAt(2).setBackgroundColor(getResources().getColor(R.color.light_orange));
			mTabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(3).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(4).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(5).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(6).setBackgroundColor(Color.TRANSPARENT);
			return;
		}
		if(tabId.equals(STYLER)){
			mTabHost.getTabWidget().getChildAt(3).setBackgroundColor(getResources().getColor(R.color.light_orange));
			mTabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(4).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(5).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(6).setBackgroundColor(Color.TRANSPARENT);
			mBuffer = new View[mListStyleLenght];
			return;
		}
		if(tabId.equals(MYSTYLE)){
			mTabHost.getTabWidget().getChildAt(4).setBackgroundColor(getResources().getColor(R.color.light_orange));
			mTabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(3).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(5).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(6).setBackgroundColor(Color.TRANSPARENT);
			mBuffer = new View[mListMyStyleLenght];
			return;
		}
		if(tabId.equals(MYSHOPPING)){
			mTabHost.getTabWidget().getChildAt(5).setBackgroundColor(getResources().getColor(R.color.light_orange));
			mTabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(3).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(4).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(6).setBackgroundColor(Color.TRANSPARENT);
			mBuffer = new View[mListFavorLenght];
		}
		if(tabId.equals(SETTING)){
			mTabHost.getTabWidget().getChildAt(6).setBackgroundColor(getResources().getColor(R.color.light_orange));
			mTabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(3).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(4).setBackgroundColor(Color.TRANSPARENT);
			mTabHost.getTabWidget().getChildAt(5).setBackgroundColor(Color.TRANSPARENT);
			return;
		}
	}

}
